fix: Optional[None] used as default value in tracer + max_separation - #675
Merged
Conversation
Optional[None] evaluates to NoneType, a truthy class object, so these defaults silently passed `is not None` guards: the tracer's early-exit block ran on every default call (comparing plane_index == NoneType, always False) and SourceMaxSeparation's default only worked because np.isclose(NoneType, z) raises the TypeError the except clause catches. A real None preserves behavior at all three sites. Closes #674 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes three sites that used the typing construct
Optional[None]as a default value (it evaluates toNoneType, a truthy class object that passesis not Noneguards):autolens/lens/tracer.py—traced_grid_2d_list_from(..., plane_index_limit: Optional[int] = None)autolens/lens/tracer_util.py— same signature fix in the module-level functionautolens/point/max_separation.py—SourceMaxSeparation(..., plane_redshift: Optional[float] = None)Behavior is preserved at all three sites (verified by reading the callees): the tracer's early-exit guard previously ran on every default call but compared
plane_index == NoneType(always False), andSourceMaxSeparation's default only worked becausenp.isclose(NoneType, z)raises the sameTypeErrorthatnp.isclose(None, z)does, hitting the existingexcept TypeErrorfallback toplane_index = -1.Sweep of PyAutoGalaxy, PyAutoArray and PyAutoFit found no further sites. Found while re-syncing the pedagogical code copies in autolens_workspace#413 (issue #674).
Test Plan
python -m pytest test_autolens/lens/ test_autolens/point/— 200 passed🤖 Generated with Claude Code